// pages/userDetail/userDetail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: wx.getStorageSync('userInfo'),
    newUsername: '',
    newPassword: '',
    newPhone: '',
    newEmail: '',
    newSex: '',
    newAvatar: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  formSubmit(e) {
    console.log(e)
    var that = this
    var user = {
      id: wx.getStorageSync('userInfo').id,
      username: e.detail.value.newUsername,
      password: '$2a$10$U86vFNULfBu5b2Ii.0R6HeBudKpLG4DhAwxTq23UAy/.vARC7/wXe',
      phone: e.detail.value.newPhone,
      email: e.detail.value.newEmail,
      sex: e.detail.value.newSex,
      avatar: e.detail.value.newAvatar,
      status: 1,
      level: '青铜'
    }
    wx.request({
      url: 'http://localhost:8081/api/userInfo/addOrUpdate',
      method: 'POST',
      data: user,
      header: {
        'token': wx.getStorageSync('token')
      },
      success: function (res) {
        if (res.data.code == 10000) {
          wx.request({
            url: 'http://localhost:8081/api/userInfo/getUserInfoDetail/'+wx.getStorageSync('userInfo').id,
            method: 'GET',
            header: {
              'token': wx.getStorageSync('token')
            },
            success:function(res){
              wx.setStorageSync('userInfo', res.data.result)
              wx.setStorageSync('username', res.data.result.username)
              wx.switchTab({
                url: '../mine/mine',
              })
            }
          })
          
        }
      }
    })
  },

  changeInfo() {
    var user = {
      id: wx.ge
    }
  },

  inputUsername(e) {
    var that = this
    that.setData({
      newUsername: e.detail.value
    })
  },

  inputPassword(e) {
    var that = this
    that.setData({
      newPassword: e.detail.value
    })
  },

  inputPhone(e) {
    var that = this
    that.setData({
      newPhone: e.detail.value
    })
  },

  inputEmail(e) {
    var that = this
    that.setData({
      newEmail: e.detail.value
    })
  },

  inputSex(e) {
    var that = this
    that.setData({
      newSex: e.detail.value
    })
  },

  inputAvatar(e) {
    var that = this
    that.setData({
      newAvatar: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})